package cn.usain.controller;

import cn.usain.pojo.Emp;
import cn.usain.service.EmpService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class EmpController {
    @Autowired
    private EmpService empService;

    @RequestMapping("findPage")
    public String findPage(Model model, Page page, Emp emp){
        Page<Emp> empPage = new Page<>(page.getCurrent(),3);
        LambdaQueryWrapper<Emp> queryWrapper = new LambdaQueryWrapper<>();
        if(emp.getDname()!=null&&emp.getDname()!=""){
            queryWrapper.like(Emp::getDname,emp.getDname());
        }
        if(emp.getEname()!=null&&emp.getEname()!=""){
            queryWrapper.like(Emp::getEname,emp.getEname());
        }
        Page<Emp> page1=empService.findAll(empPage,queryWrapper);
        model.addAttribute("list",page1);
        return "emp";
    }
    @GetMapping("del")
    public String del(Integer eid){
        empService.del(eid);
    return "redirect:findPage";
    }
}
